def use_open_r():
  file=open('file2','r',encoding='utf-8')
  txt=file.read()
  print(txt)
  file.close()

def use_open_rw():
     file = open('file2', 'r+', encoding='utf-8')
     txt = file.write("今天是一个好天气")
     print(txt)
     file.close()
def use_open_a():
 #使用a，追加方式
  file = open('file2', 'a', encoding='utf-8')
  nums = file.write("hello")
  print(nums)
  file.close()
def use_open_w():
     file=open('dir1/file3.txt','w',encoding='utf-8')#在目录下创建文件
     file.close()
if __name__=='__main__':
    use_open_rw()
    use_open_a()
    use_open_w()